package com.test5;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

/**
 * 实现对象的序列化
 */
public class ObjectOutputStreamTest {
    public static void main(String[] args) throws Exception {
        FileOutputStream fos = new FileOutputStream("C:\\Users\\LDH\\Desktop\\test.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        //序列化（写入操作）
        Students s1 = new Students("张三",20);
        Students s2 = new Students("李四",20);
        ArrayList<Students> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        oos.writeObject(list);
        oos.close();
        System.out.println("序列化ok");
    }
}
